<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class Queue {
            constructor() {
                this.item = [];
            }
            enqueue(element) {
                this.item.push(element);
            }
            dequeue() {
                return this.item.shift();
            }
            peek() {
                if (this.item.length === 0) {
                    return undefined;
                } else {
                    return this.item[0];
                }
            }
            isEmpty() {
                return this.item.length === 0;
            }
            size() {
                return this.item.length;
            }
            toString() {
                this.item.toString();
            }
        }

        function playgame(playerlist, num) {
            const queue = new Queue();
            for (let i = 0; i < playerlist.length; i++) {
                queue.enqueue(playerlist[i]);
            }
            while (queue.size() > 1) {
                for (let i = 0; i < num - 1; i++) {
                    queue.enqueue(queue.dequeue());
                }
                let out = queue.dequeue();
                console.log('淘汰' + out);
            }
            console.log('胜利' + queue.item);

        }
        const player = ['a', 'b', 'c', 'd', 'e', 'f'];
        const num = 1;
        playgame(player, num);
        // const queue = new Queue();
        // queue.enqueue('cn');
        // queue.enqueue('us');
        // queue.enqueue('uk');
        // queue.enqueue('jp');
        // console.log(queue.item);
        // console.log(queue.dequeue());
        // console.log(queue.peek());
        // console.log(queue.isEmpty());
        // console.log(queue.size());
    </script>
</body>

</html>